package com.ruoyi.stat.employee.service.impl;

import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.tools.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.stat.employee.domain.EmployeeStat;
import com.ruoyi.stat.employee.domain.bo.EmployeeStatBo;
import com.ruoyi.stat.employee.mapper.EmployeeStatMapper;
import com.ruoyi.stat.employee.service.IEmployeeStatService;

import lombok.RequiredArgsConstructor;

/**
 * 人员统计数据汇总Service业务层处理
 *
 * @author cc
 * @date 2023-04-28
 */
@RequiredArgsConstructor
@Service
public class EmployeeStatServiceImpl implements IEmployeeStatService {

	private final EmployeeStatMapper baseMapper;

//    /**
//     * 查询人员统计数据汇总
//     */
//    @Override
//    public EmployeeStatVo queryById(Date queryTime){
//        return baseMapper.selectVoById(queryTime);
//    }
//
//    /**
//     * 查询人员统计数据汇总列表
//     */
//    @Override
//    public TableDataInfo<EmployeeStatVo> queryPageList(EmployeeStatBo bo, PageQuery pageQuery) {
//        LambdaQueryWrapper<EmployeeStat> lqw = buildQueryWrapper(bo);
//        Page<EmployeeStatVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
//        return TableDataInfo.build(result);
//    }
//
//    /**
//     * 查询人员统计数据汇总列表
//     */
//    @Override
//    public List<EmployeeStatVo> queryList(EmployeeStatBo bo) {
//        LambdaQueryWrapper<EmployeeStat> lqw = buildQueryWrapper(bo);
//        return baseMapper.selectVoList(lqw);
//    }

	private LambdaQueryWrapper<EmployeeStat> buildQueryWrapper(EmployeeStatBo bo) {
		Map<String, Object> params = bo.getParams();
		LambdaQueryWrapper<EmployeeStat> lqw = Wrappers.lambdaQuery();
		lqw.eq(bo.getQueryTime() != null, EmployeeStat::getQueryTime, bo.getQueryTime());
		lqw.eq(bo.getServiceType() != null, EmployeeStat::getServiceType, bo.getServiceType());
		lqw.eq(StringUtils.isNotBlank(bo.getServiceTypeName()), EmployeeStat::getServiceTypeName,
				bo.getServiceTypeName());
		lqw.eq(bo.getYear() != null, EmployeeStat::getYear, bo.getYear());
		lqw.eq(bo.getMonth() != null, EmployeeStat::getMonth, bo.getMonth());
		lqw.eq(bo.getDay() != null, EmployeeStat::getDay, bo.getDay());
		return lqw;
	}

	@Override
	public int createStatData(String queryTime) {
		if (StringUtils.isEmpty(queryTime)) {
			queryTime = DateUtils.getCurrDate();
		}
		LambdaQueryWrapper<EmployeeStat> lqw = Wrappers.lambdaQuery();
		lqw.eq(EmployeeStat::getQueryTime, queryTime);
		this.baseMapper.delete(lqw);
		return this.baseMapper.createStatDate(queryTime);
	}

//    /**
//     * 新增人员统计数据汇总
//     */
//    @Override
//    public Boolean insertByBo(EmployeeStatBo bo) {
//        EmployeeStat add = BeanUtil.toBean(bo, EmployeeStat.class);
//        validEntityBeforeSave(add);
//        boolean flag = baseMapper.insert(add) > 0;
//        if (flag) {
//            bo.setQueryTime(add.getQueryTime());
//        }
//        return flag;
//    }
//
//    /**
//     * 修改人员统计数据汇总
//     */
//    @Override
//    public Boolean updateByBo(EmployeeStatBo bo) {
//        EmployeeStat update = BeanUtil.toBean(bo, EmployeeStat.class);
//        validEntityBeforeSave(update);
//        return baseMapper.updateById(update) > 0;
//    }
//
//    /**
//     * 保存前的数据校验
//     */
//    private void validEntityBeforeSave(EmployeeStat entity){
//        //TODO 做一些数据校验,如唯一约束
//    }
//
//    /**
//     * 批量删除人员统计数据汇总
//     */
//    @Override
//    public Boolean deleteWithValidByIds(Collection<Date> ids, Boolean isValid) {
//        if(isValid){
//            //TODO 做一些业务上的校验,判断是否需要校验
//        }
//        return baseMapper.deleteBatchIds(ids) > 0;
//    }
}
